package web;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.IAlbum;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import dao.IAlbumDAO;

/**
 * @spring.bean name="albumController"
 * @spring.property name="albumService" ref="ALBUM_SERVICE"
 * @author ipeel
 *
 */
public class AlbumController implements Controller {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
    private IAlbumDAO albumService;
    
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	Integer albumId = new Integer(request.getParameter("albumId"));
    	IAlbum album = albumService.getAlbumById(albumId);    	
	    
    	Map<String, Object> beans = new HashMap<String, Object>();
    	beans.put("album", album);
    	
        return new ModelAndView(IConstants.Views.ALBUM, beans);
    }

	/**
	 * @return Returns the albumService.
	 */
	public IAlbumDAO getAlbumService() {
		return albumService;
	}

	/**
	 * @param albumService The albumService to set.
	 */
	public void setAlbumService(IAlbumDAO albumService) {
		this.albumService = albumService;
	}
}